import { _decorator, Component, Node } from 'cc';
import Constants from '../data/Constans';
const { ccclass, property } = _decorator;

@ccclass('UILobby')
export class UILobby extends Component {
    @property({
        type: Node,
        tooltip: '背包'
    })
    knapsack: Node = null;

    @property({
        type: Node,
        tooltip: '修炼'
    })
    practice: Node = null;

    @property({
        type: Node,
        tooltip: '武林'
    })
    wulin: Node = null;

    @property({
        type: Node,
        tooltip: '宗门'
    })
    sect: Node = null;

    @property({
        type: Node,
        tooltip: '集市'
    })
    market: Node = null;

    @property(Node)
    topnumber: Node = null;

    @property(Node)
    middlenumber: Node = null;

    private _oY: number = -59.96;
    private _nY: number = -40.769;

    private _pageButtonList: any = [Node];

    start() {
        this._pageButtonList = [this.knapsack, this.practice, this.wulin, this.sect, this.market];
        this.wulin.setScale(1.2, 1.2, 1.2);
        this.wulin.setPosition(this.wulin.position.x, this._nY, 0);
    }

    // 监听免费抽奖
    onLuckDrawButton(): void {
        printLog('免费抽奖');
    }

    // 监听排行榜
    onRankingListButton(): void {
        printLog('排行榜');
    }

    // 监听好友助力
    onHelpButton(): void {
        printLog('好友助力');
    }

    // 监听免费签到
    onSiginButton(): void {
        printLog('免费签到');
    }

    // 监听日常签到
    onDailySiginButton(): void {
        printLog('日常签到');
    }

    // 监听神器礼包
    onGiftButton(): void {
        printLog('神器礼包');
    }

    // 监听订阅有礼
    onSubscribeButton(): void {
        printLog('订阅有礼');
    }

    // 监听切换页面
    onPageButton(event, customEventData): void {

        // 重置按钮状态
        for (let index = 0; index < this._pageButtonList.length; index++) {
            this._pageButtonList[index].setScale(1, 1, 1);
            this._pageButtonList[index].setPosition(this._pageButtonList[index].position.x, this._oY, 0);
        }

        // 设置按钮状态
        switch (customEventData) {
            case '0':
                this._changePageButtonState(0);
                break;
            case '1':
                this._changePageButtonState(1);
                break;
            case '2':
                this._changePageButtonState(2);
                break;
            case '3':
                this._changePageButtonState(3);
                break;
            case '4':
                this._changePageButtonState(4);
                break;
        }
    }

    // 设置按钮状态
    private _changePageButtonState(index): void {
        this._pageButtonList[index].setScale(1.2, 1.2, 1.2);
        this._pageButtonList[index].setPosition(this._pageButtonList[index].position.x, this._nY, 0);
    }

    // 监听进入游戏
    onStartGameButton(event, customEventData): void {
        // 设置按钮状态
        switch (customEventData) {
            case '1':
                printLog('进入第1章');
                Constants.OnFire.emit(Constants.EventName.GO_GAME, { key: true });
                break;
            case '2':
                printLog('进入第2章');
                break;
            case '3':
                printLog('进入第3章');
                break;
            case '4':
                printLog('进入第4章');
                break;
        }
    }
}
